﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Diagnostics;

using System.Windows.Forms;

namespace PrimeFactorization
{
    public partial class Secondary_AC_Form : Form
    {
        public Secondary_AC_Form()
        {
            InitializeComponent();
        }
        public class ChangeInACEntry
        {
            public int NewNumber{get; set;}
        };
        public delegate void ChangeInACEntryEvenHandler(object sender, ChangeInACEntry args);
        public event ChangeInACEntryEvenHandler ChangeInAC_Event;


        FactorsOfANumber FactorClass = new FactorsOfANumber();
        private void Secondary_AC_Form_Load(object sender, EventArgs e)
        {

        }
        

        public void ACENTRY_ValueChanged(object sender, EventArgs e)
        {
            if (ChangeInAC_Event != null)
            {
                ChangeInACEntry Change = new ChangeInACEntry();
                Change.NewNumber = Convert.ToInt32(ACENTRY.Value);
                ChangeInAC_Event(this, Change);
            }
          
        }

        private void FindBXTerms_Click(object sender, EventArgs e)
        {
            RecomendationBox.Visible = false;
            MathHelpLink.Visible = false;
            string[] ReturnedFactors = new string[1000];
            ReturnedFactors = FactorClass.factors_of_number(true, Convert.ToInt32(ACENTRY.Value), Convert.ToInt32(ACVALUE.Value));
            BXSolutionsListBox.Items.Clear();

            foreach (string Factor in ReturnedFactors)
            {
                if (Factor != null)
                {
                    BXSolutionsListBox.Items.Add(Factor.ToString());
                }


            }
            if (BXSolutionsListBox.Items.Count == 0)
            {
                RecomendationBox.Visible = true;
                MathHelpLink.Visible = true;
                MathHelpLink.BringToFront();

            }
        }

        private void MathHelpLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            try
            {
                Process.Start("http://www.khanacademy.org/");


            }
            catch
            {
                MessageBox.Show("Sorry, your security settings do not allow me to open your web browser to khanacademy.org");


            }
        }

        private void ACVALUE_ValueChanged(object sender, EventArgs e)
        {
            FindBXTerms_Click(this, null);
        }

        private void KeyPress_CheckForEnter(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter)
            {

                FindBXTerms_Click(this, null);
            }
        }

        private void RecomendationBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        public Color ChangeBackColorForXP
        {

            get { return label1.BackColor; }
            set
            {
                label1.BackColor = value;
                label2.BackColor = value;
                label3.BackColor = value;
                FindBXTerms.FlatStyle = FlatStyle.System;
                Settings1 settings = new Settings1();

                if (settings.WarnOnXP == true)
                {
                    XPCompatibility MessageXP = new XPCompatibility();
                    MessageXP.ShowDialog();
                }

               
            
            }

        }

     

      

       

    }
}
